package com.mercury.security.service;

import com.mercury.base.result.ResultVo;
import com.mercury.system.api.client.UserFeignClient;
import com.mercury.system.api.model.dto.UserAuthDto;
import lombok.SneakyThrows;
import lombok.extern.slf4j.Slf4j;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

/**
 * 用来根据用户名 来获取用户信息
 *
 * @author mercury
 */
@Service
@Slf4j
public class SysUserDetailsServiceImpl implements SysUserDetailsService {

    @Resource
    private UserFeignClient userFeignClient;

    @Override
    @SneakyThrows
    public UserDetails loadUserByUsername(String username) {
        // 后面从管理端获取用户信息
        ResultVo<UserAuthDto> result = userFeignClient.getUserByUsername(username);
        return getUserDetails(result);
    }

}